package com.lt.member;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import code.lewdy.db.Database;
import code.lewdy.db.HibernateTemple;
import code.lewdy.db.JdbcUtil;
import code.lewdy.util.FormatUtil;

/**会员统计
 * @author Administrator
 *
 */
@Entity
@Table
public class MemberStatistics {
	
	private Long id;
	private int fatherId; //父id
	private int ownerId;
	private String ownerName;
	private int lowerMemberCount; //下级数量
	private Double totalWinAmount;  //总赢亏
	private Double totalReturnAmount; //总返点
	private Double totalRewardAmout;  //总中奖金额
	private Double totalBetAmount; //总投注金额
	private Double totalRecharge; //充值
	private Double totalTixian; //提现
	
	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public int getOwnerId() {
		return ownerId;
	}
	public void setOwnerId(int ownerId) {
		this.ownerId = ownerId;
	}
	@Column(length=30)
	public String getOwnerName() {
		return ownerName;
	}
	public void setOwnerName(String ownerName) {
		this.ownerName = ownerName;
	}
	public int getLowerMemberCount() {
		return lowerMemberCount;
	}
	public void setLowerMemberCount(int lowerMemberCount) {
		this.lowerMemberCount = lowerMemberCount;
	}
	public Double getTotalWinAmount() {
		totalWinAmount = totalWinAmount==null ? 0D : totalWinAmount;
		totalWinAmount = FormatUtil.formatDecimal(totalWinAmount, 2);
		return totalWinAmount;
	}
	public void setTotalWinAmount(Double totalWinAmount) {
		this.totalWinAmount = totalWinAmount;
	}
	public Double getTotalReturnAmount() {
		totalReturnAmount = totalReturnAmount==null ? 0D : totalReturnAmount;
		totalReturnAmount = FormatUtil.formatDecimal(totalReturnAmount, 2);
		return totalReturnAmount;
	}
	public void setTotalReturnAmount(Double totalReturnAmount) {
		this.totalReturnAmount = totalReturnAmount;
	}
	public Double getTotalRewardAmout() {
		totalRewardAmout = totalRewardAmout==null ? 0D : totalRewardAmout;
		totalRewardAmout = FormatUtil.formatDecimal(totalRewardAmout, 2);
		return totalRewardAmout;
	}
	public void setTotalRewardAmout(Double totalRewardAmout) {
		this.totalRewardAmout = totalRewardAmout;
	}
	public Double getTotalBetAmount() {
		totalBetAmount = totalBetAmount==null ? 0D : totalBetAmount;
		totalBetAmount = FormatUtil.formatDecimal(totalBetAmount, 2);
		return totalBetAmount;
	}
	public void setTotalBetAmount(Double totalBetAmount) {
		this.totalBetAmount = totalBetAmount;
	}
	
	public static void main(String[] args) {
		JdbcUtil jdbc = new JdbcUtil(Database.TYPE_SQLSERVER);
		List<Member> ms = (ArrayList<Member>) jdbc.list(Member.class.getName(), "", 1, 1000);
		Member m = null;
		int uid = 0;
		Long id  = 0L;
		for(int i=0; i<ms.size(); i++){
			m = ms.get(i);
			uid = m.getId();
			MemberStatistics mts = (MemberStatistics) jdbc.getEntityBySQL(MemberStatistics.class.getName(), 
					"select * from MemberStatistics where ownerId="+uid);
			mts.setFatherId(m.getFatherId());
			HibernateTemple.update(mts);
			//System.out.println("tongji:"+id);
		}
	}
	public void setFatherId(int fatherId) {
		this.fatherId = fatherId;
	}
	public int getFatherId() {
		return fatherId;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "{ownerId="+this.getOwnerId()+",ownerName="+this.getOwnerName()
			+",lowerMemberCount="+this.getLowerMemberCount()+",totalWinAmount="+this.getTotalWinAmount()+
			"}";
	}
	public void setTotalRecharge(Double totalRecharge) {
		this.totalRecharge = totalRecharge;
	}
	public Double getTotalRecharge() {
		return totalRecharge;
	}
	public void setTotalTixian(Double totalTixian) {
		this.totalTixian = totalTixian;
	}
	public Double getTotalTixian() {
		return totalTixian;
	}
	
	
}
